package com.astrob.model;

import java.io.Serializable;
import java.text.SimpleDateFormat;
import java.util.Date;

public class HistoryData implements Serializable {
	private static final long serialVersionUID = 2L;

	public double lon;
	public double lat;
	public String name;
	public String address;
	public String phoneNum;
	public int eid;
	public long currentTimeMillis;
	public String countryID = "";
	public String pcode = "";

	public HistoryData() {
		revert();
	}
	
	public boolean isValid(){
		if(name.length() == 0){
			return false;
		}
		return true;
	}
	public void revert(){
		name = "";
		address = "";
		phoneNum = "";
		lon = 180.0;
		lat = 90.0;
		eid = 0;
		pcode = "";
		countryID = "";
	}

	public LonLat getLl() {
		return new LonLat(lon, lat);
	}

	public void setLl(LonLat pos) {
		lon = pos.GetLon();
		lat = pos.GetLat();
	}

	public String getName() {
		return name;
	}

	public void setName(String name) {
		this.name = name;
	}

	public String getAddress() {
		return address;
	}

	public void setAddress(String address) {
		this.address = address;
	}

	public String getPhoneNum() {
		return phoneNum;
	}

	public void setPhoneNum(String phoneNum) {
		this.phoneNum = phoneNum;
	}

	public long currentTimeMillis() {
		return currentTimeMillis;
	}

	public void setCurrentTimeMillis(long currentTimeMillis) {
		this.currentTimeMillis = currentTimeMillis;
	}
	
	public String getDataTime(){
		SimpleDateFormat formatter = new SimpleDateFormat(
				"yyyy-MM-dd HH:mm:ss");
		Date curDate = new Date(currentTimeMillis);
		String res = formatter.format(curDate);
		return res;
	}

	@Override
	public boolean equals(Object obj) {
		if (this == obj)
			return true;
		if (obj == null)
			return false;
		if (getClass() != obj.getClass())
			return false;

		HistoryData other = (HistoryData) obj;
		if (Double.doubleToLongBits(lat) != Double.doubleToLongBits(other.lat))
			return false;
		if (Double.doubleToLongBits(lon) != Double.doubleToLongBits(other.lon))
			return false;

		if (name == null) {
			if (other.name != null)
				return false;
		} else if (!name.equals(other.name))
			return false;

		return true;
	}

	public void setEid(int eid) {
		this.eid = eid;
	}

	public int getEid() {
		return eid;
	}
}
